package com.iyao_app.mvp.signlist;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.animation.AlphaAnimation;
import com.amap.api.maps.model.animation.AnimationSet;
import com.amap.api.maps.model.animation.ScaleAnimation;
import com.iyao_app.R;
import com.iyao_app.adapter.SignLinDIAdapter;
import com.iyao_app.adapter.SignMapAdapter;
import com.iyao_app.base.BaseActivityWithHead;
import com.iyao_app.entry.PageInfo;
import com.iyao_app.entry.PreviewData;
import com.iyao_app.entry.ProCities;
import com.iyao_app.entry.ResultModel;
import com.iyao_app.entry.ShareData;
import com.iyao_app.entry.SignMapData;
import com.iyao_app.entry.StoryData;
import com.iyao_app.entry.StoryDetail;
import com.iyao_app.http.NetCallBack;
import com.iyao_app.http.NetUtils;
import com.iyao_app.mvp.preview.ImageViewPagerActivity;
import com.iyao_app.util.Contants;
import com.iyao_app.util.TimeFormat;
import com.iyao_app.util.ToastUtil;
import com.iyao_app.view.NestedExpandaleListView;
import com.iyao_app.view.OnImageClickListener;
import com.iyaowoqu.base_library.util.LogUtil;
import com.iyaowoqu.base_library.util.PopupWindowUtils;
import com.iyaowoqu.base_library.util.TimeUtils;
import com.iyaowoqu.base_library.util.Utils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

import org.reactivestreams.Publisher;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
 * 作者 :  胡家兵
 * 时间 :  2017/12/14.
 */

public class SignMapListActivity extends BaseActivityWithHead implements OnLoadmoreListener, AMapLocationListener {


    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.iv_next)
    ImageView mIvNext;
    @BindView(R.id.mapView)
    TextureMapView mMapView;
    @BindView(R.id.expandable_list_view)
    NestedExpandaleListView mExpandableListView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout mRefreshLayout;
    @BindView(R.id.lin_qian_dao)
    LinearLayout mLinQianDao;
    @BindView(R.id.lin_ling_di)
    LinearLayout mLinLingDi;
    @BindView(R.id.lin_root)
    LinearLayout mLinRoot;
    @BindView(R.id.lin_empty)
    LinearLayout mLinEmpty;
    @BindView(R.id.lin_content)
    LinearLayout mLinContent;

    private int page = 1;
    private PageInfo pageInfo;
    private final int pageSize = 10;

    private AMap aMap;
    private String id;
    private SignMapAdapter signAdapter;
    private SignLinDIAdapter signLinDIAdapter;
    private LatLng currentLng;
    private BitmapDescriptor myDescrip;
    private final int QIAN_DAO = 0;
    private final int LIAN_DI = 1;
    private int type = QIAN_DAO;
    private ShareData shareUrl;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_map);
        ButterKnife.bind(this);
        init(savedInstanceState);
    }

    private void init(@Nullable Bundle savedInstanceState) {
        id = getIntent().getStringExtra(Contants.TYPE);

        signAdapter = new SignMapAdapter(null);
        signLinDIAdapter = new SignLinDIAdapter(null);
        signAdapter.setOnImageClickListener(new OnImageClickListener() {
            @Override
            public void onImageClick(List<String> list, int position) {
                PreviewData previewData = new PreviewData();
                previewData.image = list;
                previewData.position = position;
                Intent intent = new Intent(SignMapListActivity.this, ImageViewPagerActivity.class);
                intent.putExtra(Contants.CLASS_TYPE, previewData);
                startActivity(intent);
            }
        });
        mExpandableListView.setAdapter(signAdapter);
        setTitleTV("签到");
        setNextImage(R.mipmap.ic_zhuangfa);
        onNextClick(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            share();
                        }
                    }
        );
        initMap(savedInstanceState);
        mRefreshLayout.setOnLoadmoreListener(this);
        showDialog();
        getQianDaoData(true);

    }


    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;
    //声明AMapLocationClientOption对象
    public AMapLocationClientOption mLocationOption = null;


    private void location() {

        //初始化定位
        mLocationClient = new AMapLocationClient(getApplicationContext());
        //设置定位回调监听
        mLocationClient.setLocationListener(this);


        //初始化AMapLocationClientOption对象
        mLocationOption = new AMapLocationClientOption();
        //设置定位模式为AMapLocationMode.Hight_Accuracy，高精度模式。
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);


        //获取一次定位结果：
        //该方法默认为false。
        mLocationOption.setOnceLocation(true);

        //获取最近3s内精度最高的一次定位结果：
        //设置setOnceLocationLatest(boolean b)接口为true，启动定位时SDK会返回最近3s内精度最高的一次定位结果。如果设置其为true，setOnceLocation(boolean b)接口也会被设置为true，反之不会，默认为false。
        mLocationOption.setOnceLocationLatest(false);

        //设置是否返回地址信息（默认返回地址信息）
        mLocationOption.setNeedAddress(true);

        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);

        //初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点，定位点依照设备方向旋转，并且会跟随设备移动。（1秒1次定位）如果不设置myLocationType，默认也会执行此种模式。
//        myLocationStyle = new MyLocationStyle();
//        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW);//连续定位、且将视角移动到地图中心点，定位蓝点跟随设备移动。（1秒1次定位）
//        //        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE);//连续定位、且将视角移动到地图中心点，地图依照设备方向旋转，定位点会跟随设备移动。（1秒1次定位）
//        //        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点，定位点依照设备方向旋转，并且会跟随设备移动。（1秒1次定位）默认执行此种模式。
//        myLocationStyle.strokeColor(Color.TRANSPARENT);
//        myLocationStyle.radiusFillColor(Color.TRANSPARENT);
//        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_my_location));
//        aMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style

        //启动定位
        mLocationClient.startLocation();
    }

    private void initMap(Bundle savedInstanceState) {
        //在activity执行onCreate时执行mMapView.onCreate(savedInstanceState)，创建地图
        mMapView.onCreate(savedInstanceState);
        //初始化地图控制器对象
        if (aMap == null) {
            aMap = mMapView.getMap();
        }
        blackMap();
        aMap.moveCamera(CameraUpdateFactory.zoomTo(15));
        aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
        aMap.setMyLocationEnabled(false);// 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
        aMap.getUiSettings().setZoomControlsEnabled(false);
//        aMap.getUiSettings().setAllGesturesEnabled(false);
        aMap.getUiSettings().setRotateGesturesEnabled(false);
        location();
    }


    private void blackMap() {
        try {
            //开启自定义样式
            aMap.setMapCustomEnable(true);
            //加载个性化的地图底图数据
            aMap.setCustomMapStylePath(Environment.getExternalStorageDirectory()
                    + File.separator + "style/mystyle_sdk_1511952973_0100.data");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        for (Marker marker : aMap.getMapScreenMarkers()) {

            marker.remove();
        }
        mMapView.onDestroy();


    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mMapView.onResume();
        blackMap();
    }

    private boolean noMore = false;

    private void getQianDaoData(final boolean isRefesh) {
        if (isRefesh) {
            page = 1;
        } else {
            page++;
        }
        NetUtils.getInstance().getEventList(id, null, "1", page, pageSize, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {
                closeDialog();
                if (code == Contants.SUCCESS_CODE) {
                    if (model != null) {
                        StoryData storyData = model.getModel();
                        if (storyData != null) {
                            List<StoryDetail> list = storyData.list;
                            pageInfo = storyData.pageInfo;
                            if (pageInfo.pageTotal <= page) {
                                noMore = true;
                                mRefreshLayout.finishLoadmoreWithNoMoreData();
                            } else {
                                noMore = false;
                            }
                            if (isRefesh) {
                                mRefreshLayout.finishRefresh();
                            } else {
                                mRefreshLayout.finishLoadmore();
                            }
                            if (list == null || list.size() == 0) {
                                if (isRefesh) {
                                    mLinEmpty.setVisibility(View.VISIBLE);
                                    mLinContent.setVisibility(View.GONE);
                                }
                                mRefreshLayout.finishLoadmoreWithNoMoreData();
                            } else {
                                if (isRefesh) {
                                    signAdapter.getData().clear();
                                }
                                mLinEmpty.setVisibility(View.GONE);
                                mLinContent.setVisibility(View.VISIBLE);
                                dealData(list, isRefesh);
                            }
                        } else {
                            if (isRefesh) {
                                mLinEmpty.setVisibility(View.VISIBLE);
                                mLinContent.setVisibility(View.GONE);
                            }
                        }
                    } else {
                        if (isRefesh) {
                            mLinEmpty.setVisibility(View.VISIBLE);
                            mLinContent.setVisibility(View.GONE);
                        }
                    }
                }
            }

            @Override
            public void onFail(String message, int code) {
                closeDialog();
                if (isRefesh) {
                    mRefreshLayout.finishRefresh();
                } else {
                    mRefreshLayout.finishLoadmore();
                }
            }
        }, StoryData.class);
    }

    private void getLinDiData(final boolean isRefesh) {
        NetUtils.getInstance().manorList(id, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {
                if (code == Contants.SUCCESS_CODE) {
                    if (model != null) {
                        StoryData storyData = model.getModel();
                        if (storyData != null) {
                            final List<ProCities> list = storyData.proCities;
                            pageInfo = storyData.pageInfo;

                            if (isRefesh) {
                                mRefreshLayout.finishRefresh();
                            } else {
                                mRefreshLayout.finishLoadmore();
                            }
                            if (list == null && list.size() == 0) {
                                mRefreshLayout.finishLoadmoreWithNoMoreData();
                            } else {
                                if (list.size() < pageSize) {
                                    noMore = true;
                                    mRefreshLayout.finishLoadmoreWithNoMoreData();
                                } else {
                                    noMore = false;
                                    mRefreshLayout.finishLoadmore();
                                }
                                if (isRefesh) {
                                    signLinDIAdapter.getData().clear();
                                }
                                signLinDIAdapter.addData(list);

                                if (signLinDIAdapter.getData().size() > 0) {
                                    if (noMore) {
                                        ProCities proCities = new ProCities();
                                        proCities.proCityInfo = "哎吆, 没有更多了哦~";
                                        signLinDIAdapter.getData().add(proCities);
                                        signLinDIAdapter.notifyDataSetChanged();
                                    }

                                }
                                if (signLinDIAdapter.getData() != null && signLinDIAdapter.getData().size() > 0) {
                                    aMap.clear();
                                    drawMyLocation(currentLng);
                                    List<ProCities> data = signLinDIAdapter.getData();
                                    if (data != null && data.size() > 0) {
                                        for (int i = 0; i < signAdapter.getData().size(); i++) {
                                            mExpandableListView.expandGroup(i);
                                        }

                                        for (ProCities datum : data) {
                                            if (datum != null && datum.mans != null && datum.mans.size() > 0) {
                                                final List<ProCities.MansBean> mans = datum.mans;
                                                Flowable.fromArray(mans).concatMap(new Function<List<ProCities.MansBean>, Publisher<ProCities.MansBean>>() {

                                                    @Override
                                                    public Publisher<ProCities.MansBean> apply(List<ProCities.MansBean> makerInfos) throws Exception {
                                                        return Flowable.fromIterable(mans);
                                                    }
                                                }).subscribeOn(Schedulers.newThread())
                                                        .observeOn(AndroidSchedulers.mainThread())
                                                        .subscribe(new Consumer<ProCities.MansBean>() {
                                                            @Override
                                                            public void accept(ProCities.MansBean o) throws Exception {
                                                                downLoadImg(o);
                                                            }
                                                        });
                                            }
                                        }
                                    }

                                }

                            }
                        }
                    }

                }
            }

            @Override
            public void onFail(String message, int code) {
                if (isRefesh) {
                    mRefreshLayout.finishRefresh();
                } else {
                    mRefreshLayout.finishLoadmore();
                }
            }
        }, StoryData.class);
    }

    private void downLoadImg(ProCities.MansBean o) {

        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromResource(R.mipmap.ic_sign_);
        MarkerOptions markerOption = new MarkerOptions();
        markerOption.position(new LatLng(o.latitude, o.longitude));
        markerOption.draggable(false);//设置Marker可拖动
        markerOption.icon(bitmapDescriptor);
        // 将Marker设置为贴地显示，可以双指下拉地图查看效果
        markerOption.setFlat(false);//设置marker平贴地图效果
        markerOption.anchor(0.5f, 1.0f);

        AnimationSet animationSet = new AnimationSet(true);
        ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
        animationSet.addAnimation(alphaAnimation);
        animationSet.addAnimation(scaleAnimation);
        long duration = 1000L;
        animationSet.setDuration(duration);
        animationSet.setInterpolator(new BounceInterpolator());
        Marker marker = aMap.addMarker(markerOption);
        marker.setAnimation(animationSet);
        marker.setTitle(o.sceneId);
        marker.startAnimation();
    }


    Map<String, List<StoryDetail>> map = null;
    List<SignMapData> mapData = new ArrayList<>();

    private void dealData(final List<StoryDetail> list, final boolean isRefesh) {

        if (list != null && list.size() > 0) {
            if (map == null) {
                map = new LinkedHashMap<>();
            }
            if (isRefesh) {
                if (map.size() > 0) {
                    map.clear();
                }
            }
            for (int i = 0; i < list.size(); i++) {
                StoryDetail storyDetail = list.get(i);
                String signTime = TimeFormat.getSignTime(storyDetail.createTime) + String.format("   星期%s", TimeUtils.getChineseWeek(storyDetail.createTime).substring(1, 2));
                LogUtil.e("===signTime==" + signTime);
                if (map.containsKey(signTime)) {
                    List<StoryDetail> details = map.get(signTime);
                    details.add(storyDetail);
                    map.put(signTime, details);
                } else {
                    List<StoryDetail> details = new ArrayList<>();
                    details.add(storyDetail);
                    map.put(signTime, details);
                }
            }


            if (signAdapter.getData().size() > 0) {
                signAdapter.getData().clear();
            }
            mapData.clear();
            for (Map.Entry<String, List<StoryDetail>> entry : map.entrySet()) {
                SignMapData signMapData = new SignMapData();
                signMapData.time = entry.getKey();
                signMapData.list = entry.getValue();
                mapData.add(signMapData);
            }

            if (noMore) {
                SignMapData data = new SignMapData();
                data.time = "哎吆, 没有更多了哦~";
                mapData.add(data);
            }
            signAdapter.addData(mapData);
            if (signAdapter.getData().size() > 0) {
                try {
                    for (int i = 0; i < signAdapter.getData().size(); i++) {
                        mExpandableListView.expandGroup(i);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            Flowable.fromArray(list).concatMap(new Function<List<StoryDetail>, Publisher<StoryDetail>>() {

                @Override
                public Publisher<StoryDetail> apply(List<StoryDetail> makerInfos) throws Exception {
                    return Flowable.fromIterable(list);
                }
            }).subscribeOn(Schedulers.newThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<StoryDetail>() {
                        @Override
                        public void accept(StoryDetail o) throws Exception {
                            downLoadImg(o);
                        }
                    });
        }
    }

    private void downLoadImg(final StoryDetail o) {

        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromResource(R.mipmap.ic_sign_);
        MarkerOptions markerOption = new MarkerOptions();
        markerOption.position(new LatLng(o.latitude, o.longitude));
        markerOption.draggable(false);//设置Marker可拖动
        markerOption.icon(bitmapDescriptor);
        // 将Marker设置为贴地显示，可以双指下拉地图查看效果
        markerOption.setFlat(false);//设置marker平贴地图效果
        markerOption.anchor(0.5f, 1.0f);

        AnimationSet animationSet = new AnimationSet(true);
        ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
        animationSet.addAnimation(alphaAnimation);
        animationSet.addAnimation(scaleAnimation);
        long duration = 1000L;
        animationSet.setDuration(duration);
        animationSet.setInterpolator(new BounceInterpolator());
        Marker marker = aMap.addMarker(markerOption);
        marker.setAnimation(animationSet);
        marker.setTitle(String.valueOf(o.id));
        marker.startAnimation();
    }

    @Override
    public void onLoadmore(RefreshLayout refreshlayout) {
        getQianDaoData(false);
    }

    @Override
    public void onLocationChanged(AMapLocation aMapLocation) {
        if (aMapLocation == null || aMapLocation.getErrorCode() != 0) {
            //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
            LogUtil.e("定位失败");
            ToastUtil.showToast(this, "获取当前位置信息失败!");
            return;
        }
        if (aMapLocation.getErrorCode() == 0) {
            if (currentLng == null) {
                currentLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
                setLocationChange(currentLng);
            } else {
                if (currentLng.latitude == aMapLocation.getLatitude() && currentLng.longitude == aMapLocation.getLongitude()) {//坐标一样
                    LogUtil.e("定位坐标一样");
                } else {
                    currentLng = null;

                    currentLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
                    setLocationChange(currentLng);
                }
            }
        }
    }

    private void setLocationChange(LatLng currentLng) {
        //清除所有maker
        aMap.clear();
        drawMyLocation(currentLng);
    }

    private void drawMyLocation(final LatLng latLng) {
        //参数依次是：视角调整区域的中心点坐标、希望调整到的缩放级别、俯仰角0°~45°（垂直与地图时为0）、偏航角 0~360° (正北方为0)
        CameraUpdate mCameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(latLng, 15, 0, 0));
        //AMap类中提供，带有移动过程的动画
        aMap.animateCamera(mCameraUpdate, 500, new AMap.CancelableCallback() {
            @Override
            public void onFinish() {
                if (myDescrip == null) {
                    myDescrip = BitmapDescriptorFactory.fromResource(R.mipmap.ic_sign_);
                }
                MarkerOptions markerOption = new MarkerOptions();
                markerOption.position(latLng);
                markerOption.draggable(false);//设置Marker可拖动
                markerOption.icon(myDescrip);
                // 将Marker设置为贴地显示，可以双指下拉地图查看效果
                markerOption.setFlat(false);//设置marker平贴地图效果
                markerOption.anchor(0.5f, 0.5f);
                Marker marker = aMap.addMarker(markerOption);
                marker.setTitle("我的位置");

            }

            @Override
            public void onCancel() {

            }
        });
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (mLocationClient != null)
            mLocationClient.stopLocation();//停止定位后，本地定位服务并不会被销毁
    }

    @OnClick({R.id.lin_qian_dao, R.id.lin_ling_di})
    public void onViewClicked(View view) {
        ExpandableListAdapter expandableListAdapter = mExpandableListView.getExpandableListAdapter();
        switch (view.getId()) {
            case R.id.lin_qian_dao:
                if (expandableListAdapter instanceof SignMapAdapter) {
                    LogUtil.e("===instanceof=SignMapAdapter=");
                } else {
                    mExpandableListView.setAdapter(signAdapter);
                    mRefreshLayout.setEnableLoadmore(true);
                    getQianDaoData(true);
                }
                break;
            case R.id.lin_ling_di:
                if (expandableListAdapter instanceof SignLinDIAdapter) {
                    LogUtil.e("===instanceof=SignMapAdapter=");
                } else {
                    mExpandableListView.setAdapter(signLinDIAdapter);
                    mRefreshLayout.setEnableLoadmore(true);
                    getLinDiData(true);

                }
                break;
        }
    }

    private void share() {
        NetUtils.getInstance().share(id, "3", null, null, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {
                if (code == Contants.SUCCESS_CODE) {
                    if (model != null) {
                        shareUrl = model.getModel();
                        if (shareUrl != null) {
                            final PopupWindowUtils popupWindowUtils = PopupWindowUtils.getInstance();
                            popupWindowUtils.attachActivity(SignMapListActivity.this, R.layout.pop_share, mLinRoot)
                                    .wiewSize(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
                                    .location(Gravity.BOTTOM, 0, Utils.getBottomStatusHeight(SignMapListActivity.this))
                                    .focuseAble(true)
                                    .Animation(PopupWindowUtils.ANIMATION_BOTTOM)
                                    .setPopupWindowItemViewClickListener(new PopupWindowUtils.SetonPopWindowItemViewClickListenter() {
                                        @Override
                                        public void onPopWindowItemViewClickListener(int id) {

                                            boolean install = UMShareAPI.get(SignMapListActivity.this).isInstall(SignMapListActivity.this, SHARE_MEDIA.WEIXIN);
                                            if (install) {
                                                UMImage umImage = new UMImage(SignMapListActivity.this, R.mipmap.logo);
                                                UMWeb web = new UMWeb(shareUrl.shareUrl);
                                                web.setTitle("“哎吆我去”邀您来玩");//标题
                                                web.setThumb(umImage);  //缩略图
                                                web.setDescription("一款好玩儿的交友平台，给你不一样的赶脚！");//描述
                                                switch (id) {
                                                    case R.id.tv_friend:

                                                        new ShareAction(SignMapListActivity.this)
                                                                .withMedia(web)
                                                                .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE)
                                                                .share();

                                                        break;
                                                    case R.id.tv_weixin:
                                                        new ShareAction(SignMapListActivity.this)
                                                                .withMedia(web)
                                                                .setCallback(umShareListener)
                                                                .setPlatform(SHARE_MEDIA.WEIXIN)
                                                                .share();
                                                        break;
                                                }
                                            } else {
                                                Toast.makeText(SignMapListActivity.this, "请先安装微信客户端", Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    }, R.id.tv_friend, R.id.tv_weixin)
                                    .show();
                        }
                    }


                }
            }

            @Override
            public void onFail(String message, int code) {

            }
        }, ShareData.class);

    }


    private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {

        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            LogUtil.e("plat" + "============" + "platform" + platform);

            Toast.makeText(SignMapListActivity.this, " 分享成功啦", Toast.LENGTH_SHORT).show();
            shareUpdate();
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(SignMapListActivity.this, " 分享失败啦", Toast.LENGTH_SHORT).show();
            if (t != null) {
                LogUtil.e("throw" + "============" + "throw:" + t.getMessage());
            }
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(SignMapListActivity.this, " 分享取消了", Toast.LENGTH_SHORT).show();
        }
    };

    private void shareUpdate() {
        NetUtils.getInstance().shareUpdate(shareUrl.shareId, new NetCallBack() {
            @Override
            public void onSuccess(String message, int code, String response, ResultModel model) {

            }

            @Override
            public void onFail(String message, int code) {

            }
        }, null);
    }

}
